<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link href="/erp/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/font/css/font-awesome.min.css"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/erp/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="/erp/js/jquery-1.9.1.min.js"></script>
    <script src="/erp/assets/js/bootstrap.min.js"></script>
    <script src="/erp/assets/js/typeahead-bs2.min.js"></script>
    <script src="/erp/assets/js/jquery.dataTables.min.js"></script>
    <script src="/erp/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/erp/assets/layer/layer.js" type="text/javascript"></script>
    <script src="/erp/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="/erp/js/displayPart.js" type="text/javascript"></script>
</head>
<body>
<div class="add_menber" id="add_menber_style">
    <ul class=" page-content">
        <div class="Operate_cont clearfix">
            <table class="table table-striped table-bordered table-hover" id="sample-table2">
                <thead>
                <tr>
                    <th width="70">商品ID</th>
                    <th width="100">订单ID</th>
                    <th width="100">商品名称</th>
                    <th width="100">仓库名称</th>
                    <th width="100">状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </ul>
</div>
<script>
    var p;
    $.ajax({
        url: '/io-warehouse/warehouseAll',
        type: 'post',
        contentType: 'application/json',
        dataType: 'json',
        success: function (res) {
            p = res;
        }
    })


    var oTable1 = $('#sample-table2').DataTable({
        "serverSide": false,     // true表示使用后台分页
        ajax: {
            "url": "/io-warehouse/outAll",  // 异步传输的后端接口url
            "type": "POST",  // 请求方式
            "dataSrc": ''
        },
        "bStateSave": true,//状态保存
        'autoWidth': true,
        "columns": [
            {
                "data": "pid"
            },
            {
                "data": "oid"
            },
            {"data": "pname"},
            {
                "data": "pid",
                "createdCell": function (td, cellData, rowData, row, col) {
                    //加载仓库
                    var select = $('<select class="ck"></select>');
                    for (var c in p) {
                        $(select).append("<option value='" + p[c].id + "'>" + p[c].warehouseName + "</option>")
                    }
                    $(td).empty().append(select);
                }
            },

            {
                "data":"pid",
                "createdCell": function (td, cellData, rowData, row, col) {
                    $(td).empty().append('<span class="td-status">未确定</span>')
                }
            },

            {
                "data":"pid",
                "createdCell": function (td, cellData, rowData, row, col) {
                    $(td).empty().append('<a onClick="member_stop(this)" href="javascript:;" title="出库" class="btn btn-xs btn-success"><i class="icon-ok bigger-120"></i></a>');
                }
            }

        ]
    });

    //出库按钮
    function member_stop(obj){
        var tds = $(obj).parent().parent().find("td");
        console.log("xxx");
        var row = {
            pid : $(tds[0]).text(),
            oid :$(tds[1]).text(),
            name: $(tds[2]).text(),
            ck: $(tds[3]).children().val(),
        };
        //发送出库请求
        $.post("/io-warehouse/outAdd",row,function (res) {
            if(res.flag){
                layer.msg(res.message,{icon: 6,time:1000});
                $(obj).parent().prev().find(".td-status").html('<span class="label label-success radius">已出库</span>');
                $(obj).remove();
                $("#hidden",window.parent.document).click();
            }else {
                layer.msg(res.message,{icon: 5,time:1000});
            }
        })

    }

</script>
</body>
</html>